package com.qiaofang.applet.common.util;

import org.apache.commons.lang3.StringUtils;

public class ImageUtil {
    public final static Integer PHOTO_WIDTH_GENERAL = 960;
    public final static Integer PHOTO_HEIGTH_GENERAL = 640;

    public final static String WH = "?";
    public final static String NAME = "imageView2";
    public final static String WIDTH = "w";
    public final static String HEIGHT = "h";
    public final static String TYPE = "1";

    public static final int PREVIEW_H = 400;
    public static final int PREVIEW_W = 600;

    public static final String index_name = "?imageMogr2";

    public static final String reduce_parameter = "/thumbnail/";

    public static final String watermark_imageUrl = "";

    public static String getPhotoThumbnail() {
        return WH + NAME + "/" + TYPE + "/" + WIDTH + "/" + PHOTO_WIDTH_GENERAL + "/" + HEIGHT + "/" + PHOTO_HEIGTH_GENERAL;
    }

    /**
     * vr和视频的预览图大小
     * @param img
     * @return
     */
    public static String replaceImageSize(String img){
        String returnImg = "";
        if(StringUtils.isNotBlank(img)){
            int num = img.indexOf(index_name);
            String suffix = index_name + reduce_parameter + PREVIEW_W + "x" + PREVIEW_H;
            if(num != -1){
                returnImg = StringUtils.substring(img,0,num) + suffix;
            }else{
                returnImg = img + suffix;
            }
        }
        return returnImg;
    }
}
